package com.idanchuang.component.gauss;

import com.idanchuang.component.gauss.aspect.IdempotentAspect;
import com.idanchuang.component.gauss.config.IdempotentConfig;
import com.idanchuang.component.gauss.service.IdempotentService;
import com.idanchuang.component.gauss.service.UniqueIdempotentService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: chac
 * @PackageName: com.idanchuang.component.gauss
 * @ClassName: ComponentGaussAutoConfiguration
 * @Description:
 * @Date: 2021/2/5 13:57
 */
@Configuration
public class ComponentGaussAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(RestTemplate.class)
    public RestTemplate restTemplate() {
        return new RestTemplateBuilder().build();
    }

    @Bean
    public IdempotentConfig idempotentConfig() {
        return new IdempotentConfig();
    }

    @Bean
    public IdempotentService idempotentService(IdempotentConfig idempotentConfig,
                                               RestTemplate restTemplate) {
        return new IdempotentService(idempotentConfig, restTemplate);
    }

    @Bean
    public UniqueIdempotentService uniqueIdempotentService(IdempotentConfig idempotentConfig,
                                                           RestTemplate restTemplate) {
        return new UniqueIdempotentService(idempotentConfig, restTemplate);
    }

    @Bean
    public IdempotentAspect idempotentAspect(IdempotentService idempotentService) {
        return new IdempotentAspect(idempotentService);
    }

}
